package com.huohuzhihui.web.controller.system;

import com.huohuzhihui.common.core.controller.BaseController;
import com.huohuzhihui.common.utils.DateUtils;
import com.huohuzhihui.douyin.domain.DouyinUserVideo;
import com.huohuzhihui.douyin.service.IDouyinUserVideoService;
import com.huohuzhihui.merchant.domain.MerActivityBrowse;
import com.huohuzhihui.merchant.domain.MerCouponGet;
import com.huohuzhihui.merchant.service.IMerActivityBrowseService;
import com.huohuzhihui.merchant.service.IMerCouponGetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 看板
 */
@RestController
@RequestMapping("/system/dashboard")
public class DashboardController extends BaseController {
    @Autowired
    private IMerActivityBrowseService merActivityBrowseService;
    @Autowired
    private IDouyinUserVideoService douyinUserVideoService;
    @Autowired
    private IMerCouponGetService merCouponGetService;
    @GetMapping("/init")
    public Map<String,Object> init()
    {
        Map<String,Object> result = new HashMap<>();
        Date today = DateUtils.initDateByDay();//今日
        Date tomorrow = DateUtils.addDays(today,1);//明日
        Date yestoday = DateUtils.addDays(today,-1);//昨日

        //活动数据
        //今日浏览
        MerActivityBrowse merActivityBrowse = new MerActivityBrowse();
        merActivityBrowse.setBeginTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",today));
        merActivityBrowse.setEndTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",tomorrow));
        long todayBrowses = merActivityBrowseService.selectMerActivityBrowseCount(merActivityBrowse);
        result.put("todayBrowses",todayBrowses);
        //昨日浏览
        merActivityBrowse.setBeginTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",yestoday));
        merActivityBrowse.setEndTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",today));
        long yestodayBrowses = merActivityBrowseService.selectMerActivityBrowseCount(merActivityBrowse);
        result.put("yestodayBrowses",yestodayBrowses);
        //今日转发
        DouyinUserVideo douyinUserVideo = new DouyinUserVideo();
        douyinUserVideo.setBeginTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",today));
        douyinUserVideo.setEndTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",tomorrow));
        long todayVideos = douyinUserVideoService.selectDouyinUserVideoCount(douyinUserVideo);
        result.put("todayVideos",todayVideos);
        //今日转发
        douyinUserVideo.setBeginTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",yestoday));
        douyinUserVideo.setEndTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",today));
        long yestodayVideos = douyinUserVideoService.selectDouyinUserVideoCount(douyinUserVideo);
        result.put("yestodayVideos",yestodayVideos);

        //优惠券统计
        //今日领取
        MerCouponGet merCouponGet = new MerCouponGet();
        merCouponGet.setBeginTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",today));
        merCouponGet.setEndTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",tomorrow));
        long todayCoupons = merCouponGetService.selectMerCouponGetCount(merCouponGet);
        result.put("todayCoupons",todayCoupons);
        //昨日领取
        merCouponGet.setBeginTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",yestoday));
        merCouponGet.setEndTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",today));
        long yestodayCoupons = merCouponGetService.selectMerCouponGetCount(merCouponGet);
        result.put("yestodayCoupons",yestodayCoupons);

        //今日使用
        merCouponGet.setBeginTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",today));
        merCouponGet.setEndTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",tomorrow));
        merCouponGet.setUseStatus(1);
        long todayUseCoupons = merCouponGetService.selectMerCouponGetCount(merCouponGet);
        result.put("todayUseCoupons",todayUseCoupons);
        //昨日使用
        merCouponGet.setUseStatus(1);
        merCouponGet.setBeginTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",yestoday));
        merCouponGet.setEndTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",today));
        long yestodayUseCoupons = merCouponGetService.selectMerCouponGetCount(merCouponGet);
        result.put("yestodayUseCoupons",yestodayUseCoupons);
        return result;
    }
}
